package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.service.RoleService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserInfoController {
    @Reference
    private RoleService roleService;
    @RequestMapping("/findUsername")
    public Result findUsername(){
        User user= (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return new Result(true,null,user.getUsername());
    }
    @RequestMapping("/findUserRole")
    public Result findUserRole(String username){

        List<Map> roles = roleService.findRoleAndPermissionByName(username);
        System.out.println(roles);
        return new Result(true,null,roles);
    }
    @RequestMapping("/findroleByname")
    public Result findroleByname(String name){

       String roleName=roleService.findRolenameByUname(name);
        System.out.println(roleName);
        return new Result(true,null,roleName);
    }


}
